home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 1999 November / SGI IRIX 6.5 Applications 1999 November.iso / dev / java_dev.idb / usr / java / include / irix / sysmacros_md.h.z / sysmacros_md.h
Encoding:
C/C++ Source or Header  |  1998-07-14  |  5.4 KB  |  176 lines

  1. /*
  2.  * @(#)sysmacros_md.h    1.16 97/10/07
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. #ifndef _SOLARIS_SYSMACROS_MD_H_
  24. #define _SOLARIS_SYSMACROS_MD_H_
  25.  
  26. /*
  27.  * Because these are used directly as function ptrs, just redefine the name
  28.  */
  29. #define sysMalloc    malloc
  30. #define sysFree        free
  31. #define sysCalloc    calloc
  32. #define sysRealloc    realloc
  33.  
  34. /* A macro for sneaking into a sys_mon_t to get the owner sys_thread_t */
  35. #define sysMonitorOwner(mid)   ((mid)->monitor_owner)
  36.  
  37. #ifdef DEBUG
  38. extern void DumpThreads(void);
  39. void panic (const char *, ...);
  40. #if defined(JAVA) && !defined(NATIVE)
  41. #define sysAssert(expression) {        \
  42.     if (!(expression)) {        \
  43.     if (SCHED_LOCKED())  SCHED_UNLOCK(); \
  44.     DumpThreads();            \
  45.     panic("\"%s\", line %d: assertion failure\n", __FILE__, __LINE__); \
  46.     }                    \
  47. }
  48. #else /* !(defined(JAVA) && !defined(NATIVE)) */
  49. #define sysAssert(expression) {        \
  50.     if (!(expression)) {        \
  51.     DumpThreads();            \
  52.     panic("\"%s\", line %d: assertion failure\n", __FILE__, __LINE__); \
  53.     }                    \
  54. }
  55. #endif /* !(defined(JAVA) && !defined(NATIVE)) */
  56. #else
  57. #define sysAssert(expression) 0
  58. #endif
  59.  
  60. /*
  61.  * Check whether an exception occurred.  This also gives us the oppor-
  62.  * tunity to use the already-required exception check as a trap for other
  63.  * system-specific conditions.
  64.  */
  65. #define sysCheckException(ee) \
  66.     if (!exceptionOccurred(ee)) { \
  67.        continue; \
  68.     }
  69.  
  70. /*
  71.  * Case insensitive compare of ASCII strings
  72.  */
  73. #define sysStricmp(a, b)        strcasecmp(a, b)
  74.  
  75. /*
  76.  * File system macros
  77.  */
  78. #define sysOpen(_path, _oflag, _mode)    open(_path, _oflag, _mode)
  79. #define sysRead(_fd, _buf, _n)        read(_fd, _buf, _n)
  80. #define sysWrite(_fd, _buf, _n)        write(_fd, _buf, _n)
  81. #define sysClose(_fd)            close(_fd)
  82. #define sysAccess(_path, _mode)        access(_path, _mode)
  83. #define sysStat(_path, _buf)        stat(_path, _buf)
  84. #define sysMkdir(_path, _mode)        mkdir(_path, _mode)
  85. #define sysUnlink(_path)        unlink(_path)
  86. #define sysIsAbsolute(_path)        (*(_path) == '/')
  87. #define sysCloseDir(_dir)        closedir(_dir)
  88. #define sysOpenDir(_path)        opendir(_path)
  89. #define sysRmdir(_dir)                  remove(_dir)
  90. #define sysNativePath(path)            (path) 
  91. #define sysSeek(fd, offset, whence)    lseek(fd, offset, whence)
  92. #define sysRename(s, d)            rename(s, d)
  93.  
  94. /*
  95.  * Set up thread-local storage for second order monitor cache.  The
  96.  * number of words of thread-local storage must be a power of 2!
  97.  */
  98. #define SYS_TLS_MONCACHE 8 /* must be power of 2 */
  99. #define sysCurrentCacheKey(tid) (tid->cacheKey)
  100. #define sysLocalMonCache(tid, hash) (tid->monitorCache[hash])
  101.  
  102. /*
  103.  * Solaris always runs in Total Store Order mode for Sparc and
  104.  * Intel doesn't seem to support a weak consistency model for MP
  105.  * so we define this to do nothing.
  106.  */
  107. #define sysStoreBarrier() 0
  108.  
  109. /*
  110.  * Simple, fast recursive lock for the monitor cache.
  111.  *
  112.  * This is threads package specific, whereas sysmacros.h is not, but
  113.  * could be simplified if sysmacros.h ever specializes.
  114.  * 
  115.  * The includes for threads package-specific files are ugly here because
  116.  * this file goes into javah, which doesn't otherwise include from those
  117.  * directories.
  118.  *
  119.  * Let's face it...we need threads package-specific sys include files.
  120.  */
  121. #ifndef NATIVE
  122.  
  123. #include "../green_threads/include/schedule.h"
  124. #define sysCacheLockInit()     /* A no-op */
  125. #define sysCacheLock()        SCHED_LOCK()
  126. #define sysCacheLocked()    SCHED_LOCKED()
  127. #define sysCacheUnlock()    SCHED_UNLOCK()
  128.  
  129. /* Override the extern in sys_api.h with something faster */
  130. #define sysThreadSelf()        greenThreadSelf()
  131.  
  132. #define sysMemoryFlush() 0
  133. #define sysIsMP() 0
  134.  
  135. #else
  136.  
  137. #if defined(_COMPILER_VERSION) && (_COMPILER_VERSION>=700)
  138. #define sysMemoryFlush() __synchronize()
  139. #endif
  140.  
  141. #include "../native_threads/include/mutex_md.h"
  142.  
  143. typedef struct {
  144.     mutex_t mutex;
  145.     long entry_count;
  146.     sys_thread_t *owner;
  147. } cache_lock_t;
  148.  
  149. /*
  150.  * We do leave the mutex locked across the whole cache lock to avoid
  151.  * the extra unlock and lock that a smaller critical region would entail.
  152.  */
  153. extern cache_lock_t _moncache_lock;
  154. #define sysCacheLockInit() {   mutexInit(&_moncache_lock.mutex);    \
  155.                    _moncache_lock.entry_count = 0;        \
  156.                    _moncache_lock.owner = 0;        \
  157.                }
  158. #define sysCacheLock()     {   mutexLock(&_moncache_lock.mutex);    \
  159.                    sysAssert(_moncache_lock.entry_count >= 0);\
  160.                    if (_moncache_lock.entry_count++ == 0) {    \
  161.                   _moncache_lock.owner = sysThreadSelf();\
  162.                    }                    \
  163.                }
  164. /* Should not need locking: */
  165. #define sysCacheLocked()   (_moncache_lock.owner == sysThreadSelf())
  166. #define sysCacheUnlock()   {   sysAssert(_moncache_lock.entry_count > 0);\
  167.                    if (--_moncache_lock.entry_count == 0) {    \
  168.                   _moncache_lock.owner = 0;        \
  169.                    }                    \
  170.                    mutexUnlock(&_moncache_lock.mutex);    \
  171.                }
  172.  
  173. #endif /* NATIVE */
  174.  
  175. #endif /*_SOLARIS_SYSMACROS_MD_H_*/
  176.